// https://acm.hdu.edu.cn/showproblem.php?pid=1114

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

// 相当于已知存钱罐的重量以及每个硬币的重量
// 求在所有可能的硬币组合中，存钱最少为多少。
// 注意，这里需要保证重量完全填充好

int max_weight, n;
int dp[10005];          // dp[i] 表示重量为 i 时存钱罐的最小存款
int available[10005];   // available[i] 表示重量为 i 的存储方案是可行的
int weights[505], values[505];

int main() {
    int t, a, b;
    scanf("%d", &t);
    while (t--) {
        scanf("%d %d", &a, &b);
        max_weight = b - a;
        scanf("%d", &n);
        memset(dp, 0x3F3F3F3F, sizeof(dp));
        memset(available, 0, sizeof(dp));

        for (int i = 1; i <= n; i++) {
            scanf("%d%d", &values[i], &weights[i]);
        }
        available[0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = weights[i]; j <= max_weight; j++) {
                available[j] |= available[j - weights[i]];
            }
        }

        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = weights[i]; j <= max_weight; j++) {
                if (available[j]) {
                    dp[j] = min(dp[j], dp[j - weights[i]] + values[i]);
                }
            }
        }

        if (dp[max_weight] != 0x3F3F3F3F) {
            printf("The minimum amount of money in the piggy-bank is %d.\n", dp[max_weight]);
        } else {
            printf("This is impossible.\n");
        }
    }
    return 0;
}